Skip to main content

yButton

Description

The yButton is a clickable element with different optical styles, used to indicate its different states. The yButton can be used to trigger a user action. For example:

Basic Structure

The basic structure of the yButton shall be explained in the following. For the general structure of a yComponent please visit the YBase-components basic-structure.

Button Structure

The yButton as seen above contains a label and an left-sided and right-sided icon.

Label

The label contains the text inside the button. It is normally in the center of the component, but can also be displayed on the right or left side. By changing the inner padding of the button, the label gets moved too.

Icon

Icon Structure

The icon can be used to show an icon inside the yButton. You can have a maximum of two icons in a yButton. The icon can be before or after the text and if you want to have a yButton with one icon only, then you have to delete the text in the Label.

Properties

Through its various properties the yButton can be configured to suit your needs. The display below provides you with an overview of all the yButton properties.

Properties can be changed directly through three methods:

  • Inside the Toolbar, which is positioned in your workarea next to your component right where you need it. It shows the most important properties, thus providing a fast and efficient way to configure your component in the most basic way.
  • It may also occur in the Toolbar Extension, which is a seamless extension accesible as a dropdown item of the Toolbar. It extends the functionality of the Toolbar by providing advanced pickers for the most used properties.
  • Inside the Detail Panel, which is located in the righthand drawer. Every property of a component can be configured here.
METAread more
--y-button__component-id

The identifier of the component that is unique within a page.

--y-button__component-type

The type of the component. For this component it is -button.

--y-button__name

The custom name of the component. It serves for better identification of the component.

--y-button__version

The custom version of the Button-component. This can be used to ensure that all components work well together.

--y-button__core-theme

The CoreTheme, which will be apllied to the Button. For further information on themes visit the themes page.

--y-button__sub-theme

The subtheme subordinated to the previously specified CoreTheme, which will be apllied to the Button. For further information on themes visit the themes page.

--y-button__group-theme

The group theme is a further variation of the subtheme which is specified especially for variations of a component inside the subtheme. For further information on themes visit the Theme-Manager page.

DISPLAYread more
--y-button__display

This property specifies the display behavior of the component. This can be be set to:

  • none
  • block
  • flex
  • inline
--y-button__position

This property specifies the type of positioning method used for the component. This can be be set to:

  • static
  • relative
  • absolute
  • sticky
  • fixed
--y-button__visible

This property can toggle the visibility of the component. The two modes are completely hidden and fully shown.

SIZEread more
--y-button__min-width

The minimum value for the width of the component. This can be set in:

  • px
  • pt
  • em
  • vw
  • vh
  • %
--y-button__min-height

The minimum value for the height of the component. This can be set in:

  • px
  • pt
  • em
  • vw
  • vh
  • %
--y-button__width

The value for the width of the component. This can be set in:

  • px
  • pt
  • em
  • vw
  • vh
  • %
  • auto
--y-button__height

The value for the height of the component. This can be set in:

  • px
  • pt
  • em
  • vw
  • vh
  • %
  • auto
--y-button__max-width

The maximum value for the width of the component. This can be set in:

  • px
  • pt
  • em
  • vw
  • vh
  • %
  • none
--y-button__max-height

The maximum value for the height of the component. This can be set in:

  • px
  • pt
  • em
  • vw
  • vh
  • %
  • none
--y-button__flex

The flex property sets the length on flexible items. This sets the value in n-fold shares extrapolated to all other components with the flex display within the same container.

PLACEMENTread more
--y-button__margin-top

This property creates a space around the component, outside of the top border. This can be set in percent or pixels.

--y-button__margin-right

This property creates a space around the component, outside of the right border. This can be set in percent or pixels.

--y-button__margin-bottom

This property creates a space around the component, outside of the bottom border. This can be set in percent or pixels.

--y-button__margin-left

This property creates a space around the component, outside of the left border. This can be set in percent or pixels.

--y-button__padding-top

This property creates a space within the component, inside of the top border. This can be set in percent or pixels.

--y-button__padding-right

This property creates a space within the component, inside of the right border. This can be set in percent or pixels.

--y-button__padding-bottom

This property creates a space within the component, inside of the bottom border. This can be set in percent or pixels.

--y-button__padding-left

This property creates a space within the component, inside of the top border. This can be set in percent or pixels.

Usage

In this section you will find a collection of application scenarios and examples that illustrate how to leverage the yButton in ways that deviate from its standard behavior, as defined by yBase. This section aims to inspire and guide you through various possibilities, helping you to implement more complex or unique functionalities tailored to your specific needs. General properties that are universally applicable can be found in the yBase usage section.

Variations

Button Elevated
Elevated
Button Flat
Flat
Button Outlined
Outlined
Button Rounded
Rounded
Button Plain
Plain
genericsizeminWidth120px
stylebackgroundbgColor__normal#44ddbb
styleshadowboxShadow__normal0 3px 6px 0 rgba(16, 18, 24, 0.2)
styleborderborderRadius8px
stylelabellabel__fontColor__normal#FFFFFF

Label

Button Label
Uppercase Label
genericsizemin-width150px
stylelabellabel__font-color#FFFFFF
stylelabellabel__font-family'Roboto'
stylelabellabel__font-size20px
stylelabellabel__font-weight'bold'
stylelabellabel__text-transform'uppercase'
stylelabellabel'Submit'

Icon

Button Icon Left
iconLeft
Button Icon Both
iconBoth
Button Icon Only
iconOnly
genericsizeminWidth150px
styleiconiconPosition'iconLeft'
styleiconicon__colorPrimary#FFFFFF
styleiconiconSize16px
styleiconiconLeft'fas-fa-fish'

Calling a Custom JavaScript Function

The yButton component enables you to execute a custom JavaScript function each time it is clicked.

For instance, you could set up a function that creates a counter on the yButton, incrementing each time the yButton is pressed. Once the counter reaches the number 10, it automatically resets. The steps to achieve this are detailed below.

How to:

  1. Open the Detail Panel and proceed to Events, unfold Input to modify EvtClicked.
  2. Associate a custom JavaScript function to the yButton. This function will be invoked every time it is clicked.
  3. Include the provided JavaScript snippet below to implement a counter function.

Code example:

With this script, each click on the yButton will increment the displayed counter until it reaches 10, upon which it will display a congratulatory message and reset. The yButton background color will also change depending on the counters current state.

Button EvtClicked
// function onButton_2_EvtClicked (apiObject, component, eventData) {

let buttonText = component.get("style", "label", "label");
// Convert string to number.
let counter = Number(buttonText);
// Not a number -> reset counter.
if (Number.isNaN(counter)) {
counter = 0;
component.set(
"style",
"background",
"bgColor__normal",
new apiObject.types.colorValue("#22aaffFF")
);
component.set(
"style",
"background",
"bgColor__hover",
new apiObject.types.colorValue("#49B9ffFF")
);
}
// Increment counter.
else {
counter++;
}
// Count until ten.
if (counter == 10) {
buttonText = "Well done!";
component.set(
"style",
"background",
"bgColor__normal",
new apiObject.types.colorValue("#00ff0080")
);
component.set(
"style",
"background",
"bgColor__hover",
new apiObject.types.colorValue("#00ff00FF")
);
} else {
buttonText = counter.toString();
}
// Log counter value in browser console.
console.log(counter);
// Set property value of button.
component.set("style", "label", "label", buttonText);

// }

Hiding and Showing Popups

You can use the yButton to open and close popups.

How to:

  1. Navigate to the popup you wish to control and open its Detail Panel.
  2. Within these settings, proceed to the Links section and select Open.
  3. In this area, change Source-Link-Open to select the yButton you created earlier - the SourceLink should look like this: y-page:1:y-button:2:click.

And that's it, you can now test this functionality by entering the preview mode and clicking on the button to observe the popup's visibility change. Visit the yPopup section, if you want to know more about their behavior.

Interacting with Clipboards

You can use the yButton to control Clipboards. For example, you can set up a mechanism to delete a table entry with a simple button click.

How to:

  1. Open the Detail Panel and proceed to the events tab and locate the "Control" section. Here, you will need to enable the "Commit-Delete" option. This step empowers the yButton component with the capability to perform this functionality.
  2. Create a new Clipboard and enable the "Use Entity" toggle.
Button Clipboard useEntity
  1. Then you can click on "Entity-Properties" and edit the "Entity". This Clipboard should be linked to the entity containing the table entry you wish to delete. This way you have to fill in the data, like in the picture below.
Button Clipboard Entity
  1. The _id under "Keys" should be the entry that you wish to delete.
  2. Finally, go to the "Events", edit it and select the yButton as SourceLink-1 via the SourceLink Picker. Dont forget that the event has to be "commit-delete".
Button Clipboard SourceLink

This will establish a button that, when clicked, will delete the specified entry from your table.

If you want to know more about this topic, visit the Clipboard.

Sending an email

The yButton component can be used to send out emails.

For instance, you could create a newsletter formular with input elements and yButton to send out a confirmation mail.

How to:

  1. Create a new yInput with type text.
  2. Now select your yButton again.
  3. Open the Detail Panel and proceed to Events, unfold Input to modify EvtClicked.
  4. Associate a custom JavaScript function to the yButton. This function will be invoked every time it is clicked.
  5. Include the provided JavaScript snippet below to implement an email function.

Code example:

With this script, each click on the yButton will send out an email to the email-address which was assigned in the yInput.

Button EvtClicked
// async function onButton_2_EvtClicked (apiObject, component, eventData) {

let emailInput = apiObject.ui.getObject(3, "y-input", "y-page", 1);
let email = emailInput.get("style", "content", "valueString");

if (email.length > 0 && email.contains("@")) {
await apiObject.email.sendUserMail({
path: "[Folder in the mediamanager for your template]",
template: "[Your template]",
placeholderValues:
"{'yeet:Salutation': 'Greetings', 'yeet:FirstName': 'Lorem', 'yeet:LastName': 'Ipsum', 'yeet:RegistrationUrl': 'www.google.com', 'yeet:AdminName': 'Max Mustermann'}",
attachmentInfos:
"[{'FileName': 'mh2.png', 'Path': 'tutorialFolder', 'Content': ''}]",
recipientAddress: email,
recipientName: "Lorem Ipsum",
subject: "Complete your registration!",
userName: "testUser",
});
} else {
alert("Please enter a valid email-address!");
}

// }